<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/12
  Time: 17:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>销售对账</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/bootstrap/dist/css/bootstrap.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/pages/yzl/css/test.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/plugins/layui/css/layui.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath }/bootstrap-table/dist/bootstrap-table.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/toastr.min.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/bootstrap/dist/js/bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/bootstrap-table/dist/bootstrap-table.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/bootstrap-table/src/locale/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/plugins/layui/layui.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/toastr.min.js"></script>
    <script type="text/javascript">toastr.options.positionClass = 'toast-top-center';</script>
    <script type="text/javascript">
        $(function () {

            //1.初始化Table
            var oTable = new TableInit();
            oTable.Init();

            //2.初始化Button的点击事件
            var oButtonInit = new ButtonInit();
            oButtonInit.Init();

        });


        var TableInit = function () {
            var oTableInit = new Object();
            //初始化Table
            oTableInit.Init = function () {
                $('#tb_departments').bootstrapTable({
                    url: '${pageContext.request.contextPath }/pages/yzl/data/salesReceivable.json',         //请求后台的URL（*）
                    method: 'post',                      //请求方式（*）
                    //contentType : "application/x-www-form-urlencoded",
                    toolbar: '#toolbar',                //工具按钮用哪个容器
                    striped: true,                      //是否显示行间隔色
                    cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                    pagination: true,                   //是否显示分页（*）
                    //queryParamsType: "limit",
                    //contentType: "application/x-www-form-urlencoded",
                    sortable: false,                     //是否启用排序
                    sortOrder: "asc",                   //排序方式
                    queryParams: oTableInit.queryParams,//传递参数（*）
                    sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,                       //初始化加载第一页，默认第一页
                    pageSize: 10,                       //每页的记录行数（*）
                    pageList: [5,10,15,20],        //可供选择的每页的行数（*）
                    search: true,                       //是否显示表格搜索，此搜索是客户端搜索，不会进服务端，所以，个人感觉意义不大
                    strictSearch: true,
                    showColumns: true,                  //是否显示所有的列
                    showRefresh: true,                  //是否显示刷新按钮
                    minimumCountColumns: 2,             //最少允许的列数
                    //clickToSelect: true,                //是否启用点击选中行
                    height: 500,                        //行高，如果没有设置height属性，表格自动根据记录条数觉得表格高度
                    uniqueId: "ID",                     //每一行的唯一标识，一般为主键列
                    showToggle: true,                    //是否显示详细视图和列表视图的切换按钮
                    cardView: false,                    //是否显示详细视图
                    detailView: false,                   //是否显示父子表
                    columns: [
                    [{
                        field: 'carType',
                        title: '车种',
                        colspan: 1,
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }, {
                        field: 'numberP',
                        title: '品编',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }, {
                        field: 'nameP',
                        title: '品名',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }, {
                        field: 'unitPrice',
                        title: '单价',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }, {
                        field: 'BeginRemainingQ',
                        title: '期初结存数量',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }, {
                        field: 'BeginRemainingP',
                        title: '期初结存金额',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    },{
                        field: 'thisPeriodCollectmoney',
                        title: '本期出库',
                        align:"center",
                        rowspan: 1,
                        colspan:8,
                    },{
                        field: 'thisPeriodOutLibQ',
                        title: '本期出库数量',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }, {
                        field: 'thisPeriodOutLibP',
                        title: '本期出库金额',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    },{
                        field: 'thisPeriodSettlementQ',
                        title: '本期结算数量',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }, {
                        field: 'thisPeriodSettlementP',
                        title: '本期结算金额',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    },{
                        field: 'endOfperiodBalanceQ',
                        title: '期末结存数量',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }, {
                        field: 'endOfperiodBalanceP',
                        title: '期末结存金额',
                        rowspan: 2,
                        valign:"middle",
                        align:"center",
                    }],
                    [{
                        field: '12月1号',
                        title: '12月1号',
                        rowspan: 1,
                    },{
                        field: '12月2号',
                        title: '12月2号',
                        rowspan: 1,
                    },{
                        field: '12月3号',
                        title: '12月3号',
                        rowspan: 1,
                    },{
                        field: '12月4号',
                        title: '12月4号',
                        rowspan: 1,
                    },{
                        field: '12月5号',
                        title: '12月5号',
                        rowspan: 1,
                    },{
                        field: '12月6号',
                        title: '12月6号',
                        rowspan: 1,
                    },{
                        field: '12月7号',
                        title: '12月7号',
                        rowspan: 1,
                    },{
                        field: '12月8号',
                        title: '12月8号',
                        rowspan: 1,
                    }],
                    ]
                });
            };

            //得到查询的参数
            oTableInit.queryParams = function (params) {
                var temp = {   //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                    limit: params.limit,   //页面大小
                    offset: params.offset/params.limit+1,  //页码
                    demandDate: $("#demandDate_serch").val(),
                    produceStatus: $("#produceStatus_serch").val(),
                    outLibraryStatus: $("#outLibraryStatus_serch").val(),
                    customerId: $("#customerId_serch").val(),
                    entryPerson: $("#entryPerson_serch").val(),
                };
                return temp;
            };
            return oTableInit;
        };


        var ButtonInit = function () {

            var oInit = new Object();
            var postdata = {};

            oInit.Init = function () {
                //初始化页面上面的按钮事件
            };
            return oInit;
        };
    </script>
</head>
<body>

<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form id="formSearch" class="form-horizontal">
                <div class="form-group" style="margin-top:15px">
                    <label class="control-label col-sm-1" for="txt_search_departmentname">日期:</label>
                    <div class="col-sm-1">
                        <select id="txt_search_departmentname" name="materienumber" class="selectpicker show-tick form-control"  data-live-search="false">
                            <option>最近一天</option>
                            <option>最近一星期</option>
                            <option>最近一个月</option>
                        </select>
                    </div>
                    <label class="control-label col-sm-1" for="txt_search_statu" style="width: 30px;">从</label>
                    <div class="col-sm-2">
                        <input type="text" name="demandDate" id="demandDate_serch" lay-verify="date" placeholder="yyyy-mm-dd"
                               autocomplete="off" class="layui-input form-control"
                               onclick="layui.laydate({elem: this})">
                    </div>
                    <label class="control-label col-sm-1" for="txt_search_statu" style="width: 30px;padding-left: 0px;">至</label>
                    <div class="col-sm-2" style="padding-left: 0px;">
                        <input type="text" name="demandDate" id="demandDate_serch1" lay-verify="date" placeholder="yyyy-mm-dd"
                               autocomplete="off" class="layui-input form-control"
                               onclick="layui.laydate({elem: this})">
                    </div>
                    <div class="col-sm-1" style="text-align:left;">
                        <button type="button" style="margin-left:50px" id="btn_query" class="btn btn-primary">查询</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div id="toolbar" class="btn-group">
        <button id="btn_add" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>图形报表
        </button>
        <button id="btn_edit" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span>导出
        </button>
        <button id="btn_delete" type="button" class="btn btn-default">
            <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>打印
        </button>
    </div>

    <!--        表格           -->
    <table id="tb_departments"></table>


    <script>
        $(document).ready(function () {
            $("#btn_add").click(function () {

                $('#td_addModelTable').bootstrapTable({
                    dataType: "json",
                    method: 'get',
                    contentType: "application/x-www-form-urlencoded",
                    cache: false,
                    toolbar: '#toolbarIn',
                    url:"${pageContext.request.contextPath }/pages/yzl/data/saleOutCarList.json",
                    columns:[
                        [
                            {
                                field: 'name',
                                title: "出库单号",
                                valign:"middle",
                                align:"center",
                                colspan: 1
                            },
                            {
                                title: "00000000001",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            },
                            {
                                title: "出库日期",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            },
                            {
                                title: "2222-2-22",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            },
                            {
                                title: "制单人",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            },
                            {
                                title: "鬼",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            }
                        ],
                        [
                            {
                                field: 'name',
                                title: "客户",
                                valign:"middle",
                                align:"center",
                                colspan: 1
                            },
                            {
                                title: "鬼",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            },
                            {
                                title: "销售计划单号",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            },
                            {

                                //title: "鬼",
                                //valign:"middle",
                                field: 'aa',
                                align:"center",
                                colspan: 1,
                                formatter:function(value,row,index){
                                    var back = index;
                                    return '<a href="#" onclick="chosePlanNum(' + back + ')" >选择销售计划</a>'
                                }
                            },
                            {
                                title: "审批人",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            },
                            {
                                title: "鬼",
                                valign:"middle",
                                align:"center",
                                colspan: 1,
                            }
                        ],
                        [
                            {
                                field: 'carType',
                                title: '车种',
                                valign:"middle",
                                align:"center"
                            },
                            {
                                field: 'numberP',
                                title: '品编',
                                valign:"middle",
                                align:"center"
                            },
                            {
                                field: 'nameP',
                                title: '品名',
                                valign:"middle",
                                align:"center"
                            },
                            {
                                field: 'batchNumber',
                                title: '批号',
                                valign:"middle",
                                align:"center"
                            },
                            {
                                field: 'outQ',
                                title: '出库数量',
                                valign:"middle",
                                align:"center"
                            },
                            {
                                field: 'barderNumber',
                                title: '条码',
                                valign:"middle",
                                align:"center"
                            }
                        ]
                    ]
                });

                var allRows = $("#tb_departments").bootstrapTable("getData");
                $('#myModal').modal({
                    keyboard: true,
                })
            });
            $("#btn_edit").click(function () {

                if ($('#checkbox-id').is(':checked')) {
                    console.log(222222222222);
                }

                $('#myModalUpdate').modal({
                    keyboard: true,
                })
            });
            $("#btn_delete").click(function () {

                if ($('#checkbox-id').is(':checked')) {
                    console.log(333333333333);
                }

                $('#myModalDelete').modal({
                    keyboard: true,
                })
            });

            //选择销计划单号
            function chosePlanNum(){
                alert(1111111111);
            }

            //提交审核
            $("#btn_approved").click(function (){
                //必须选中一条数据
                var checkedItems = $('#tb_departments').bootstrapTable('getSelections');
                var checkedItem = checkedItems[0];
                if(checkedItems <= 0){
                    //$("#btn_edit").attr("data-toggle", "");
                    //$("#btn_edit").attr("data-target", "");
                    toastr.warning('请选择一行信息');
                }else{
                    console.log("checkedItems----",checkedItems);
                    var arr = filterData(checkedItems);
                    console.log("arr",arr);
                    if(arr){
                        //执行后台
                        $.ajax({
                            url:"${pageContext.request.contextPath}/yzl/orderApproveds.do",
                            type:"post",
                            data:{"arr":JSON.stringify(arr)},
                            success:function (data) {
                                if(data != 0){
                                    toastr.info('操作成功');
                                    refreshAjax();
                                }else{
                                    toastr.warning('操作失败');
                                }
                            }
                        })
                    }else{
                        toastr.warning('不能选择审核中的审核通过的');
                    }
                }
            })
        });

        //点击查询 重新请求  刷新表格
        function refreshAjax(){
            $("#tb_departments").bootstrapTable('refresh',{url : '${pageContext.request.contextPath }/yzl/customerOrderList.do'});
        }
    </script>


    <script>
        layui.use(['form', 'layedit', 'laydate'], function() {
            var form = layui.form(),
                layer = layui.layer,
                layedit = layui.layedit,
                laydate = layui.laydate;

            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');
            //自定义验证规则
            form.verify({
                title: function(value) {
                    if(value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                },
                pass: [/(.+){6,12}$/, '密码必须6到12位'],
                content: function(value) {
                    layedit.sync(editIndex);
                }
            });

            //监听提交
            form.on('submit(demo1)', function(data) {
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                return false;
            });
        });



    </script>

</body>
</html>
